<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *项目管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('start','off');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择信息！','error');
	}
}
$return['sex']=$this->sex2;
$return['pay']=$this->xinzhis;
$return['job_type']=$this->job_type;
$return['job_paytype']=$this->job_paytype;
$return['job_baotype']=$this->job_baotype;
if($_RQ['op']=='list'){
	$params=array('type'=>0);
	$params['uniacid']=$_SESSION['uniacid'];
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['name']){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	if($_RQ['city']){
		$params['city like']='%'.trim($_RQ['city']).'%';
		$return['params']['city']=$_RQ['city'];
	}
	if($_RQ['mobile']){
		$params['mobile like']='%'.trim($_RQ['mobile']).'%';
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_51job_jianli',$params,array($pindex,$psize),$total,$fields,'','createtime desc,id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('member')->member_show('','','',$item['mid']);
			$item['pcd']=json_decode($item['pcd'],true);
			if(!$item['pcd']['province'] && $item['pcd']['city']){
					if(mb_substr($item['pcd']['city'],-1)!='市'){
						$item['pcd']['city']=$item['pcd']['city'].'市';
					}
					if(mb_substr($item['pcd']['district'],-1)!='区'){
						$item['pcd']['district']=$item['pcd']['district'].'区';
					}
					$parent_code=pdo_getcolumn('core_area',array('type'=>2,'title'=>$item['pcd']['city']),'parent_code');
					$item['pcd']['province']=pdo_getcolumn('core_area',array('type'=>1,'code'=>$parent_code),'title');
					if($item['pcd']['province']){
						pdo_update('jy_51job_jianli',array('pcd'=>ijson_encode($item['pcd'])),array('id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
					}
			}
			$item['updatetime']=$item['updatetime']?:$item['createtime'];
			if(!$item['sousuo']){
				$sousuo=$item['title'].'|'.$item['name'].'|'.$item['xueinfo'].'|'.$item['xianginfo'].'|'.$item['peiinfo'].'|'.ijson_encode($item['pcd']);
				pdo_update('jy_51job_jianli',array('sousuo'=>$sousuo),array('id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'简历列表'),
		),
		'list'=>array('data'=>'list','tip'=>'<red>[温馨提示]：这里显示个人发布的简历</red>','edit'=>true,'list'=>array(
			array('name'=>'id','title'=>'ID','type'=>'string'),
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'city','title'=>'城市','type'=>'string'),
			array('name'=>'name','title'=>'姓名','type'=>'string'),
			array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('type'=>'radio','title'=>'学历','name'=>'xueli','help'=>'','options'=>'xueli'),
			array('name'=>'title','title'=>'职位意向','type'=>'string'),
			array('name'=>'age','title'=>'出生年份','type'=>'string'),
			array('name'=>'express','title'=>'工作经验','type'=>'string'),
			array('name'=>'address','title'=>'现居住地','type'=>'string'),
			array('name'=>'updatetime','title'=>'更新时间','type'=>'time'),
			array('name'=>'looks','title'=>'浏览数量','type'=>'string'),
			array('name'=>'status','title'=>'是否启用','type'=>'switch','set'=>'set'),
			array('name'=>'url','title'=>'复制链接','type'=>'copy'),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
		),'action'=>array(
			//array('type'=>'href','op'=>'tuijie','title'=>'推荐给企业'),
		)),
		'search'=>array(
			array('name'=>'mid','width'=>15,'title'=>'发布人','type'=>'choose','action'=>'core/member.get_member/'),
			array('name'=>'city','width'=>10,'title'=>'城市','type'=>'string'),
			array('name'=>'name','width'=>10,'title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','width'=>10,'title'=>'电话','type'=>'string'),
			array('name'=>'title','width'=>10,'title'=>'职位意向','type'=>'string'),
			array('name'=>'status','width'=>10,'title'=>'是否启用','type'=>'select','width'=>'15','options'=>'select_status'),
		)
	);
	$return['sex']=$this->sex;
	$return['xueli']=$this->xueli_type;
	$return['select_status']=array(array('id'=>0,'title'=>'下架'),array('id'=>1,'title'=>'上架'));
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_51job_jianli',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['pcd']=json_decode($item['pcd'],true);
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回项目列表'),
		),
		'edit'=>array(
			array('name'=>'name','title'=>'姓名','type'=>'string'),
			array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('type'=>'radio','title'=>'学历','name'=>'xueli','help'=>'','options'=>'xueli'),
			array('name'=>'title','title'=>'职位意向','type'=>'string'),
			array('type'=>'radio','title'=>'工作性质','name'=>'type','help'=>'','options'=>'job_type'),
			array('type'=>'select','title'=>'期望行业','name'=>'pid','options'=>'pids'),
			array('name'=>'price','title'=>'期望薪资','type'=>'string'),
			array('name'=>'pcd','title'=>'所属区域','type'=>'pcd'),
			array('name'=>'express','title'=>'工作经验','type'=>'string'),
			array('name'=>'age','title'=>'出生年份','type'=>'string'),
			array('name'=>'address','title'=>'现居住地','type'=>'string'),
			array('name'=>'currentstatus','title'=>'目前状态','type'=>'string'),
			array('name'=>'thumb','title'=>'形象照片','type'=>'image'),
			array('name'=>'content','title'=>'自我介绍及工作经历','type'=>'richtext'),
			array('name'=>'status','title'=>'是否启用','type'=>'switch','set'=>'set'),
		)
	);
	$return['pids']=pdo_getall('jy_51job_job_group',array('pid'=>0,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['job_type']=$this->job_type;
	$return['sex']=$this->sex;
	$return['xueli']=$this->xueli_type;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['pcd']['province']){
		exi('城市不能为空！','error');
	}
	if($postdata['pcd']){
		if($postdata['pcd']['city']){
			if($postdata['pcd']['city']=='北京市' || $postdata['pcd']['city']=='上海市' || $postdata['pcd']['city']=='天津市'){
				$address=$postdata['pcd']['city'].' 市辖区';
			}else{
				$address=$postdata['pcd']['province'].' '.$postdata['pcd']['city'];
			}
			$code=pdo_getcolumn('core_area',array('address'=>$address),'parent_code');
		}
	}
	if(!$postdata['price']){
		$pay='面议';
	}else{
		$postdata['paytype']=$postdata['paytype']?:0;
		$pay=$postdata['price'].'元/'.$this->job_paytype2[$postdata['paytype']];
	}
	$data=array(
			'title'=>trim($postdata['title']),
			'price'=>trim($postdata['price']),
			'name'=>trim($postdata['name']),
			'age'=>trim($postdata['age']),
			'education'=>trim($postdata['education']),
			'xueli'=>$postdata['xueli'],
			'express'=>trim($postdata['express']),
			'type'=>$postdata['type'],
			'mobile'=>trim($postdata['mobile']),
			'sex'=>trim($postdata['sex']),
			'address'=>trim($postdata['address']),
			'email'=>trim($postdata['email']),
			'currentstatus'=>trim($postdata['currentstatus']),
			'content'=>trim($postdata['content']),
			'pid'=>trim($postdata['pid']),
			'city'=>$postdata['pcd']['city'],
			'district'=>$postdata['pcd']['district'],
			'pcd'=>ijson_encode($postdata['pcd']),
			'status'=>trim($postdata['status']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_51job_jianli',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		$data['updatetime']=time();
		pdo_insert('jy_51job_jianli',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_51job_jianli',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的项目！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_51job_jianli',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	if(isset($post['ishot'])){
		$basic=$this->plugin_setting('basic');
		$topdays=intval($basic['topdays'])?:7;
		$topendtime=TIMESTAMP+$topdays*24*3600;
		pdo_update('jy_51job_jianli',array('ishot'=>intval($post['ishot']),'topendtime'=>$topendtime),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='tuijie'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$isadd=pdo_get('jy_51job_agentfee',array('jianliid'=>intval($post['jianliid']),'merchid'=>intval($post['merchid']),'uniacid'=>$_SESSION['uniacid']));
		if($isadd['id']){
			exi('已经推送过该简历给该企业，请勿重复推荐！','error');
		}
		if(!$post['merchid']){
			exi('请先选择推荐的企业！','error');
		}
		$data=array(
			'jianliid'=>intval($post['jianliid']),
			'merchid'=>intval($post['merchid']),
			'fee'=>$post['fee'],
			'remark'=>$post['remark'],
		);
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		pdo_insert('jy_51job_agentfee',$data);
		exi('推送成功！','','//list/');
	}
	$id=intval($_RQ['id']);
	$return['item']=array('jianliid'=>$id);	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'推送简历给企业',
	);
	$htmls['edit']=array(
		array('name'=>'merchid','title'=>'推送给企业','type'=>'choose','action'=>'jy_51job/get_merch/'),
		array('name'=>'fee','title'=>'结算金额','type'=>'unitstring','unit'=>'元'),
		array('name'=>'remark','title'=>'备注','type'=>'string'),
	);
	$return['htmls']=$htmls;
	exi($return);
}